package com.google.zxing.client;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.android.nearshop.R;
import com.dg11185.libs.network.NetClient;
import com.dg11185.nearshop.activity.BaseActivity;
import com.dg11185.nearshop.activity.shop.ShopDetailActivity;
import com.dg11185.nearshop.app.MyApplication;
import com.dg11185.nearshop.net.request.GeneralRequest;
import com.dg11185.nearshop.net.response.LoginResponse;
import com.dg11185.nearshop.net.response.NetStatus;
import com.umeng.analytics.MobclickAgent;

public class ScanSuccessActivity extends BaseActivity {

    private TextView nameTxt, urlTxt;

    private String shopName, shopId, shopUrl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.barcode_scan_success);

        shopName = getIntent().getStringExtra("shop_name");
        shopId = getIntent().getStringExtra("shop_id");
        shopUrl = getIntent().getStringExtra("shop_url");
        nameTxt = (TextView) this.findViewById(R.id.scan_success_shopname);
        urlTxt = (TextView) this.findViewById(R.id.scan_success_url);
        
        nameTxt.setText(shopName);
        urlTxt.setText(shopUrl);
        uploadScanRecord();
    }

    public void onGotoUrlClicked(View v) {
        Uri uri = Uri.parse(shopUrl);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    public void onGotoDetailClicked(View v) {
        Intent intent = new Intent(this, ShopDetailActivity.class);
        intent.putExtra("merchant_id", shopId);
        startActivity(intent);
    }

    private void uploadScanRecord() {
        LoginResponse user = MyApplication.getUser();
        GeneralRequest request = new GeneralRequest(GeneralRequest.SCAN_QR_CODE).add("userId", user.userId)
                .add("type", "1").add("targetId", shopId).encryption();
        request.setActionListener(new GeneralRequest.ActionListener<NetStatus>() {
            @Override
            public void onSuccess(NetStatus result) {

            }

            @Override
            public void onFailure(int resultCode) {
            }
        });
        NetClient.httpPost(request);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(getClass().getName());
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(getClass().getName());
        MobclickAgent.onResume(this);
    }
    
    
}